package com.anolesoft.amljmes.test.fenguangyingdu.controller;

import cn.hutool.core.bean.BeanUtil;
import com.anolesoft.amljmes.test.fenguangyingdu.dto.FenguangYingduRecordLogQueryDTO;
import com.anolesoft.amljmes.test.fenguangyingdu.service.FenguangYingduService;
import com.anolesoft.amljmes.test.fenguangyingdu.vo.FenguangYingduRecordLogQueryVO;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.HttpStatus;
import com.anolesoft.yr.util.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhj
 * @date 2021/12/22 11:33
 */
@RestController
@Slf4j
@RequestMapping("/api/fengguangyingdurecord-log")
public class FengguangYingduLogController {
    @Autowired
    private FenguangYingduService fenguangYingduService;

    @GetMapping(value = "/list")
    public AjaxResult selectPageConditonList(FenguangYingduRecordLogQueryVO fenguangYingduRecordLogQueryVO) {
        log.debug("fenguangYingduRecordLogQueryVO：{}", fenguangYingduRecordLogQueryVO);
        Integer limit = fenguangYingduRecordLogQueryVO.getPageSize();
        Integer curr = fenguangYingduRecordLogQueryVO.getPageNo();
        FenguangYingduRecordLogQueryDTO dto = BeanUtil.copyProperties(fenguangYingduRecordLogQueryVO, FenguangYingduRecordLogQueryDTO.class);
        log.debug("{}", dto);
        PageData<List<FenguangYingduRecordLogQueryDTO>> listPageData = this.fenguangYingduService.selectListByCondition(dto, limit, curr);
        List<FenguangYingduRecordLogQueryVO> vos = listPageData.getItems().stream().map(t -> BeanUtil.copyProperties(t, FenguangYingduRecordLogQueryVO.class)).collect(Collectors.toList());
        PageResult pg = new PageResult(vos, limit, curr, listPageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pg);
    }

}
